﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace InstantWatch.Controls {
	/// <summary>
	/// Interaction logic for HighlightImage.xaml
	/// </summary>
	public partial class HighlightImage : UserControl {

		#region Highlighted Routed Event
		public static readonly RoutedEvent HighlightedEvent = EventManager.RegisterRoutedEvent(
				"Highlighted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(HighlightImage));
		public event RoutedEventHandler Highlighted {
			add { AddHandler(HighlightedEvent, value); }
			remove { RemoveHandler(HighlightedEvent, value); }
		}
		#endregion

		#region Unhighlighted Routed Event
		public static readonly RoutedEvent UnhighlightedEvent = EventManager.RegisterRoutedEvent(
				"Unhighlighted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(HighlightImage));
		public event RoutedEventHandler Unhighlighted {
			add { AddHandler(UnhighlightedEvent, value); }
			remove { RemoveHandler(UnhighlightedEvent, value); }
		}
		#endregion

		#region IsHightlighted Dependency Property
		public bool IsHightlighted {
			get { return (bool)GetValue(IsHightlightedProperty); }
			set {
				SetValue(IsHightlightedProperty, value);
				if (value)
					RaiseEvent(new RoutedEventArgs(HighlightImage.HighlightedEvent));
				else
					RaiseEvent(new RoutedEventArgs(HighlightImage.UnhighlightedEvent));
			}
		}
		public static void HighlightedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
			HighlightImage img = d as HighlightImage;
			if (img == null) {
				MessageBox.Show("Null D");
				return;
			}

			if (true.Equals(e.NewValue))
				((HighlightImage)d).RaiseEvent(new RoutedEventArgs(HighlightImage.HighlightedEvent));
			else
				((HighlightImage)d).RaiseEvent(new RoutedEventArgs(HighlightImage.UnhighlightedEvent));
		}
		public static readonly DependencyProperty IsHightlightedProperty =
				DependencyProperty.Register("IsHightlighted", typeof(bool), typeof(HighlightImage), new UIPropertyMetadata(false, HighlightedChanged)); 
		#endregion



		public string ImageSource {
			get { return (string)GetValue(ImageSourceProperty); }
			set { SetValue(ImageSourceProperty, value); }
		}

		public static readonly DependencyProperty ImageSourceProperty =
				DependencyProperty.Register("ImageSource", typeof(string), typeof(HighlightImage), new UIPropertyMetadata(string.Empty));

		public double ImageWidth {
			get { return (double)GetValue(ImageWidthProperty); }
			set { SetValue(ImageWidthProperty, value); }
		}
		public static readonly DependencyProperty ImageWidthProperty =
				DependencyProperty.Register("ImageWidth", typeof(double), typeof(HighlightImage), new UIPropertyMetadata(100D));


		public HighlightImage() {
			InitializeComponent();
		}
	}
}
